//
//  UIImage+Extension.swift
//  照片选择器
//
//  Created by Tanenbaum on 15/8/8.
//  Copyright © 2015年 GZJ. All rights reserved.
//

import UIKit
extension UIImage {
    
    func scale(width: CGFloat) ->UIImage {
        
        if size.width < width {
            return self
        }
       let height = size.height * width / size.width
       let s = CGSize(width: width, height: height)
        
        UIGraphicsBeginImageContext(s)
        drawInRect(CGRect(origin: CGPointZero, size: s))
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return result
    }
}
